import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    activePath: '/home',
    auth: 1
  },
  mutations: {
    changActivePath (state, activePath) {
      state.activePath = activePath
    },
    changeAuth (state, auth) {
      state.auth = auth
    }
  },
  plugins: [createPersistedState({
    storage: window.sessionStorage,
    reducer (data) {
      return {
        // 设置只储存 state 中的 auth
        auth: data.auth
      }
    }
  })]
})

export default store
